#pragma once

#include "storage_filter.h"

#include <muduo/net/EventLoopThread.h>
#include <muduo/net/TimerId.h>

#include <mutex>
#include <unordered_map>

namespace fusion_perception {

class JitterStorageFilter : public StorageFilter {
public:
    JitterStorageFilter(size_t count);
    ~JitterStorageFilter(void);

    bool filtering(int64_t id);

private:
    void onTimeout(void);

private:
    typedef struct FilterUnit {
        size_t count { 0 };
        int64_t latestMicroTs { 0 };
    } FilterUnit;

    size_t count_ { 0 };
    std::mutex mutexLock_;
    muduo::net::TimerId timerId_;

    std::unordered_map<int64_t, FilterUnit> filterUMap_;

private:
    inline static muduo::net::EventLoopThread eventLoopThread_;
};
}